<template>
  <div>
    <h1>注册页面</h1>

    <table>
      <tr>
        <td>账号</td>
        <td>
          <input type="text" v-model="addLoginInfo.UserName" >
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="password" v-model="addLoginInfo.UserPWd" >
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="注册" @click="addLogin" >
        </td>
      </tr>
    </table>

  </div>
</template>

<script setup lang="ts">
    import router from '@/router';
import axios from 'axios';


    import {reactive,toRefs} from 'vue'

    let data:any=reactive({
      addLoginInfo:{
        UserName:'',
        UserPWd:''
      }
    })

    let {addLoginInfo} =toRefs(data);


    const addLogin=()=>{
      
      if (addLoginInfo.value.UserPWd=="") {
        return alert('登录密码不能为空');
      }
      if (addLoginInfo.value.UserName=="admin") {
        return alert('用户账号不能重复');
      }
      alert('注册成功');
      router.push('/login')

      console.log(addLoginInfo.value);
      
      axios({
        url:'/api/User/LoginAdd',
        method:'post',
        data:addLoginInfo.value
      }).then(res=>{
        alert('成功');

      }).catch(err=>{

      })
    }


</script>

<style scoped>

</style>